home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #11 / Amiga Plus CD - 2004 - No. 11.iso / AmiSoft / Comm / www / tidy_os4.lha / tidy / include / buffio.h next >
Encoding:
C/C++ Source or Header  |  2004-07-25  |  2.6 KB  |  99 lines

  1. #ifndef __BUFFIO_H__
  2. #define __BUFFIO_H__
  3.  
  4. /** @file buffio.h - Treat buffer as an I/O stream.
  5.  
  6.   (c) 1998-2004 (W3C) MIT, ERCIM, Keio University
  7.   See tidy.h for the copyright notice.
  8.  
  9.   CVS Info :
  10.  
  11.     $Author: terry_teague $ 
  12.     $Date: 2004/02/29 04:00:03 $ 
  13.     $Revision: 1.4 $ 
  14.  
  15.   Requires buffer to automatically grow as bytes are added.
  16.   Must keep track of current read and write points.
  17.  
  18. */
  19.  
  20. #include "platform.h"
  21. #include "tidy.h"
  22.  
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26.  
  27. /** TidyBuffer - A chunk of memory */
  28. TIDY_STRUCT
  29. struct _TidyBuffer 
  30. {
  31.     byte* bp;           /**< Pointer to bytes */
  32.     uint  size;         /**< # bytes currently in use */
  33.     uint  allocated;    /**< # bytes allocated */ 
  34.     uint  next;         /**< Offset of current input position */
  35. };
  36.  
  37. /** Zero out data structure */
  38. TIDY_EXPORT void tidyBufInit( TidyBuffer* buf );
  39.  
  40. /** Free current buffer, allocate given amount, reset input pointer */
  41. TIDY_EXPORT void tidyBufAlloc( TidyBuffer* buf, uint allocSize );
  42.  
  43. /** Expand buffer to given size. 
  44. **  Chunk size is minimum growth. Pass 0 for default of 256 bytes.
  45. */
  46. TIDY_EXPORT void tidyBufCheckAlloc( TidyBuffer* buf,
  47.                                     uint allocSize, uint chunkSize );
  48.  
  49. /** Free current contents and zero out */
  50. TIDY_EXPORT void tidyBufFree( TidyBuffer* buf );
  51.  
  52. /** Set buffer bytes to 0 */
  53. TIDY_EXPORT void tidyBufClear( TidyBuffer* buf );
  54.  
  55. /** Attach to existing buffer */
  56. TIDY_EXPORT void tidyBufAttach( TidyBuffer* buf, byte* bp, uint size );
  57.  
  58. /** Detach from buffer.  Caller must free. */
  59. TIDY_EXPORT void tidyBufDetach( TidyBuffer* buf );
  60.  
  61.  
  62. /** Append bytes to buffer.  Expand if necessary. */
  63. TIDY_EXPORT void tidyBufAppend( TidyBuffer* buf, void* vp, uint size );
  64.  
  65. /** Append one byte to buffer.  Expand if necessary. */
  66. TIDY_EXPORT void tidyBufPutByte( TidyBuffer* buf, byte bv );
  67.  
  68. /** Get byte from end of buffer */
  69. TIDY_EXPORT int  tidyBufPopByte( TidyBuffer* buf );
  70.  
  71.  
  72. /** Get byte from front of buffer.  Increment input offset. */
  73. TIDY_EXPORT int  tidyBufGetByte( TidyBuffer* buf );
  74.  
  75. /** At end of buffer? */
  76. TIDY_EXPORT Bool tidyBufEndOfInput( TidyBuffer* buf );
  77.  
  78. /** Put a byte back into the buffer.  Decrement input offset. */
  79. TIDY_EXPORT void tidyBufUngetByte( TidyBuffer* buf, byte bv );
  80.  
  81.  
  82. /**************
  83.    TIDY
  84. **************/
  85.  
  86. /* Forward declarations
  87. */
  88.  
  89. /** Initialize a buffer input source */
  90. TIDY_EXPORT void initInputBuffer( TidyInputSource* inp, TidyBuffer* buf );
  91.  
  92. /** Initialize a buffer output sink */
  93. TIDY_EXPORT void initOutputBuffer( TidyOutputSink* outp, TidyBuffer* buf );
  94.  
  95. #ifdef __cplusplus
  96. }
  97. #endif
  98. #endif /* __BUFFIO_H__ */
  99.